From: Florian Müllner Date: Tue, 6 Feb 2024 17:48:02 +0000 (+0100) Subject: messageTray: Add NotificationPolicy.newFromApp() X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~281^2~2^2~16 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=810391f41ee6f8e1ea89fd6e9a9170728f0ee870;p=gnome-shell.git messageTray: Add NotificationPolicy.newFromApp() We have several places where we create an application policy from an app if possible, and fall back to a generic policy otherwise. Make that more convenient by adding a small helper method. Part-of: --- diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index d5cdf686e..abdc0982a 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -161,6 +161,24 @@ export const NotificationPolicy = GObject.registerClass({ GObject.ParamFlags.READABLE, false), }, }, class NotificationPolicy extends GObject.Object { + /** + * Create a new policy for app. + * + * This will be a NotificationApplicationPolicy for valid apps, + * or a NotificationGenericPolicy otherwise. + * + * @param {Shell.App=} app + * @returns {NotificationPolicy} + */ + static newForApp(app) { + // fallback to generic policy + if (!app?.get_app_info()) + return new NotificationGenericPolicy(); + + const id = app.get_id().replace(/\.desktop$/, ''); + return new NotificationApplicationPolicy(id); + } + // Do nothing for the default policy. These methods are only useful for the // GSettings policy. store() { }